﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnimalCare.Model;

namespace AnimalCare.Service
{
    class PackagingService
    {
        public static void Insert(string packagingname)
        {
            Packaging cf = new Packaging();
            cf.Packaging_name = packagingname;
            using (var ctx = new AnimalCareDBEntities())
            {
                ctx.Packagings.AddObject(cf);
                ctx.SaveChanges();
            }
        }

        public static void Update(Packaging cf)
        {
            using (var ctx = new AnimalCareDBEntities())
            {
                var packaging = (from s in ctx.Packagings
                                 where s.packaging_id == cf.packaging_id
                                 select s).FirstOrDefault();
                packaging.Packaging_name = cf.Packaging_name;
                int num = ctx.SaveChanges();
            }
        }

        public static void Delete(int id)
        {
            try
            {
                using (var ctx = new AnimalCareDBEntities())
                {
                    var cf = (from s in ctx.Packagings
                              where s.packaging_id == id
                              select s).FirstOrDefault();
                    ctx.Packagings.DeleteObject(cf);
                    int num = ctx.SaveChanges();
                }
            }
            catch
            {
            }
        }
    }
}
